package com.cars.bim.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cars.bim.generator.entity.TbJiangEntity;
import com.cars.bim.generator.service.TbJiangService;
import com.cars.framework.common.utils.PageUtils;
import com.cars.framework.common.utils.Query;
import com.cars.framework.common.utils.R;
import com.cars.framework.modules.sys.controller.AbstractController;
import com.cars.framework.modules.sys.entity.SysUserEntity;




/**
 * 
 * 
 * @author admin
 * @email admin@gmail.com
 * @date 2018-04-18 22:45:17
 */
@RestController
@RequestMapping("/generator/tbjiang")
public class TbJiangController extends AbstractController{
	@Autowired
	private TbJiangService tbJiangService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = null;
        SysUserEntity  user =   getUser();
        if(!"admin".equals(user.getUsername())){
        	
        	params.put("name",user.getUsername());
        }
        query =  new Query(params);
		List<TbJiangEntity> tbJiangList = tbJiangService.queryList(query);
		int total = tbJiangService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(tbJiangList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Integer id){
		TbJiangEntity tbJiang = tbJiangService.queryObject(id);
		
		return R.ok().put("tbJiang", tbJiang);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody TbJiangEntity tbJiang){
		tbJiangService.save(tbJiang);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody TbJiangEntity tbJiang){
		tbJiangService.update(tbJiang);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Integer[] ids){
		tbJiangService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
